package com.dengtacj.puppeteerspider.utils;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;


public class JDBCTemplateUtil {

    private final static String   sqlUrl="jdbc:mysql://127.0.0.1:3306/db_analyse_config?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai";
    private final static String   sqlUsername="root";
    private final static String   sqlPassword="root";
    private final static String   sqlDriver="com.mysql.cj.jdbc.Driver";


    public DataSource dataSource(){

        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(sqlUrl);
        dataSource.setUsername(sqlUsername);//用户名
        dataSource.setPassword(sqlPassword);//密码
        dataSource.setDriverClassName(sqlDriver);
        dataSource.setInitialSize(2);
        dataSource.setMaxActive(20);
        dataSource.setMinIdle(0);
        dataSource.setMaxWait(60000);
        dataSource.setValidationQuery("SELECT 1");
        dataSource.setTestOnBorrow(false);
        dataSource.setTestWhileIdle(true);
        dataSource.setPoolPreparedStatements(false);
        return dataSource;
    }

    public JdbcTemplate jdbcTemplate(){
       return  new JdbcTemplate(dataSource());
    }


}
